<template>
	<view class="content">
		<view class="header">
			<view class="title">
				请选择患者信息
			</view>
			<view class="des">
				以便医生给出更准确的治疗,信息仅医生可见.
			</view>
		</view>
		<view class="list-box">
			<view class="yy-inquiry-user-info" v-for="(item,index) in itemList" @click="clickSelItem(item)">
				<view class="user-left">
					<view class="icon">
						<image v-if="item.avatar" :src="item.avatar" mode="aspectFill">
						</image>
						<image v-else src="@/static/images/f.png" mode="aspectFill"></image>
					</view>
				</view>
				<view class="user-right">
					<view class="info">
						{{ infoFormat(item) }}
					</view>
					<view class="detail">
						{{ bodyStatae(item)}}
					</view>
				</view>
			</view>
		</view>
		<!-- 添加 -->
		<view class="yy-inquiry-user-sel" @click="addPatient">
			<text class="iconfont icon-jiahao1"></text>
			<view class="">添加患者</view>
		</view>
		<view class="yy-safe-bh"></view>
	</view>
</template>

<script>
	import {
		userinfoFormat,
		userBodyStataeFormat
	} from "@/utils/format.js";
	import {
		getPatientList
	} from '@/api/inquiry.js';
	import {
		mapGetters
	} from "vuex";
	export default {
		computed: mapGetters(['isLogin', 'viewColor', 'uid','routeError']),
		data() {
			return {
				loadTitle: '加载更多',
				loading: false,
				loadend: false,
				where: {
					// 'page': 1,
					// 'limit':20,
				},
				itemList: [],
			}
		},
		onLoad() {
			if(this.routeError) {
				this.$store.commit('GO_ERROR');
				return
			}
			
			this.getList();
			
			this.$nextTick(() => {
				let that = this;
				uni.$on('yy_patient_add', () => {
					console.log('rk===>add suc')
					that.getList();
				});
			});
		},
		onPullDownRefresh() {
			console.log('rk==>refresh')
			// this.loadend = false;
			// this.where.page = 1;
			this.clickMore();
		},
		onReachBottom() {
			this.clickMore();
		},
		onUnload() {
			uni.$off('yy_patient_add');
		},
		methods: {
			/**
			 * 信息格式化
			 */
			infoFormat(info) {
				return userinfoFormat(info);
			},
			/**
			 * 状态格式化
			 */
			bodyStatae(info) {
				return userBodyStataeFormat(info);
			},
			/**
			 * 列表
			 */
			getList() {
				let that = this;
				that.where.uid = this.uid;
				getPatientList(that.where).then(res => {
					uni.stopPullDownRefresh();

					that.itemList = [];
					let resList = res.data;
					that.itemList = that.$util.SplitArray(resList, that.itemList);
					that.$set(that, 'itemList', that.itemList);

				});

			},
			/**
			 * 更多
			 */
			clickMore() {
				if (this.loadend) {
					return
				}
				this.getList();
			},
			/**
			 * 添加患者
			 */
			addPatient() {
				uni.navigateTo({
					url: '/pages/shops/subs_inquiry/addpatient/index'
				})
			},
			/**
			 * 选择
			 */
			clickSelItem(item){
				uni.$emit('yy_patient_sel',item);
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}

	.content {
		padding: 40rpx 30rpx;

		.header {
			.title {
				font-size: $yy-title-font;
				font-weight: bold;
			}

			.des {
				font-size: 25rpx;
				color: $yy-des-col;
				padding: 20rpx 0 40rpx;
			}
		}
	}
</style>
